Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Are Enum classes in Kotlin "expensive" for Android as in Java?
  • Are Enum classes in Kotlin "expensive" for Android as Java?.
  • Is it still stand to use @IntDefs or @StringDefs in Kotlin?.

When I decompile Kotlin Enum class to Java class, there still used Java Enums in the low level, which are not recommended for use in Android Development, and this made me think about this.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  1. Are Enum classes in Kotlin "expensive" for Android as Java?. Could be. I doubt whether kotlin will be able to do any optimization that java cannot.
  2. Is it still stand to use @IntDefs or @StringDefs in Kotlin?. - Not really. This is a polarising subject and many in the Android world(including me) believe that using enums should be the preferred way. I encourage you to read the following links to get a better idea.

Twitter thread by Jake Wharton

An article by Diane Hackborn and the comments

Somwhat witty reddit thread talking about optimization of enums and such

And the following answers by Jake Wharton are interesting.

Does lint support kotlin typedefs? (Lint for Kotlin won't be fully supported until AS 3.1, and we're on 3.0 still)

Do you mean typealias? If so, yes.

Will I get a lint warning for an exhaustive when when I do a return when(intDef) { .. } and accidentally omit one of the the possible types?

An else will always be required here. Not sure about the lint warning though.

Does AS have an intention (alt + enter to quickly add all variants of the intDef?

Yes.

Like right now, instead of shipping features, we're discussing when this micro-optimization should be used!

Summation of the entire enum conversation since about 2012!

I'm also wondering if a sealed class where each implementation is an object has some perf gains over an enum

None. It's effectively the exact same thing as an enum.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!